#include "gamehall.h"
#include "ui_gamehall.h"
#include"gameselect.h"
#include<QIcon>
#include<QPushButton>
#include<QPainter>
#include<QPixmap>
#include<QFont>
#include<QSound>
gamehall::gamehall(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::gamehall)
{
    ui->setupUi(this);
    //设置窗口大小
    this->setFixedSize(1000,800);
    //设置标题
    this->setWindowTitle("贪吃蛇游戏");
    //设置小图标
    this->setWindowIcon(QIcon(":res/menu.png"));

    QPushButton* startButton = new QPushButton(this);
    //设置按钮大小，标题，位置
    startButton->resize(200,80);
    startButton->setText("开始游戏");
    startButton->move(400,550);

    //设置样式
    QFont font("新宋体",20);
    startButton->setFont(font);

    //跳转
    gameSelect* gameselect = new gameSelect;
    connect(startButton,&QPushButton::clicked,[=](){
        this->close();
        //将下一个窗口设置为当前窗口一样大
        gameselect->setGeometry(this->geometry());
        gameselect->show();

        QSound::play(":res/clicked.wav");
    });
}

gamehall::~gamehall()
{
    delete ui;
}

void gamehall::paintEvent(QPaintEvent *event)
{
    (void)event;
    //定义一个画家
    QPainter painter(this);
    //布置背景
    QPixmap pixmap(":res/menu.png");
    //将背景设置到this中
    painter.drawPixmap(0,0,this->width(),this->height(),pixmap);

}

